Repository navigation
Conversation
`ocr config set providers.<name>.url` and `mcp_servers.<name>.url` both reject a value without an http(s) scheme and trim surrounding padding. `ocr config set llm.url` wrote the raw string through, so a value like `gateway.internal.com/v1` was saved as-is and only surfaced later as `Post "/gateway.internal.com/v1/v1/messages": unsupported protocol scheme ""` from the first review request; a padded value survived into the request URL as `%20`. Route the key through the same validateBaseURL the provider path uses, and validate the manual-config writer in provider_cmd.go the same way so the two writers of llm.url cannot disagree.
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
Both comments described the behavior this branch removes (a value saved verbatim and failing later). Say what the code does now.
|
Thanks for catching this. I support validating Before merging, please add For the manual wizard, I’d prefer showing the error at the URL field so users can correct a typo without re-entering their model and credentials. Please keep the save-time check as well. I’d leave stricter hostname validation, such as rejecting |
Problem
ocr config set llm.urlstores the value verbatim, while the other two URL keys of the same command (providers.<name>.url,mcp_servers.<name>.url) reject a value without an http(s) scheme and trim padding. The gap is silent: the bad value is accepted and written to~/.opencodereview/config.json, and only the first LLM request fails, with a message that names neither the config key nor the command that wrote it.Reproduced on
mainat 78c2e0e, buildingocrfrom that commit and running it against a throwawayUSERPROFILE:The hint points at the configuration and the API key, but neither is the fault; the URL is.
ocr llm testreports the same opaque message:Padding fails the same way.
ocr config set llm.url 'https://example.com/v1 'is accepted, and the trailing space reaches the request URL:The provider path already avoids both outcomes:
Change
cmd/opencodereview/config_cmd.go: thellm.urlcase now trims the value and runs it through the samevalidateBaseURLthe provider field uses, reporting it under the key the user typed. An empty value still clears the key.cmd/opencodereview/provider_cmd.go:applyManualConfigis the second writer ofllm.url(the manual tab ofocr config provider) and had the same gap; it now trims and validates the same way, so the two writers cannot disagree about what a validllm.urlis. A rejected value leaves the loaded config untouched, which is what the existing provider-write tests already assert for the other fields.A value that was already valid and unpadded is stored exactly as before.
Verification
Manual, on Windows, comparing the
mainbuild (78c2e0e) with the branch build, each against its own emptyUSERPROFILE:ocr config set llm.url <value>gateway.internal.com/v1Set llm.url = …, savedError: invalid URL for llm.url: Base URL must use http or https scheme, got "", exit 1, nothing savedftp://gateway.internal/v1Set llm.url = …, savedError: invalid URL for llm.url: Base URL must use http or https scheme, got "ftp", exit 1, nothing savedhttps://gateway.internal:8000/v1The config file each run left behind:
Tests added:
TestSetConfigValueLlmURLTrimsAndValidates(cmd/opencodereview/config_cmd_test.go): trims a valid value, clears on empty, rejectsapi.example.com/v1,ftp://…,://bad, and leaves the key unset.TestApplyManualConfig_InvalidURLandTestApplyManualConfig_TrimsURL(cmd/opencodereview/provider_cmd_test.go): the manual-config writer rejects the same values without mutating the config, and stores a padded value trimmed.Run on this branch:
go build ./...: clean.go vet ./cmd/opencodereview/: clean.go run scripts/verify-english-only.go:No unapproved non-English text in 915 scanned source files.go test -count=1 ./cmd/opencodereview/:ok … 128.131s(whole package, verbose).go test -race -count=1 ./cmd/opencodereview/: ok.gofmt -s -won the touched files produced no diff.make checkis not runnable here (nomakeon Windows), so its three steps — license-check, english-check,go mod tidy+go vet— were run individually as listed (the license script is unchanged by this PR: no new files). The pre-commitocr reviewAGENTS.md requires could not run: this environment has no LLM endpoint configured.AI disclosure
Claude (via DeepSeek Harness, model
deepseek-v4.1-flash) drafted this change and the tests. I reviewed every line, ran the before/after comparison and the test commands above myself, and can answer questions about the change without AI assistance.Related Issues
No tracking issue; found while auditing
ocr config setvalidation coverage.